<?php

declare(strict_types=1);

namespace SixShop\Wangdian\Services;

use SixShop\Wangdian\Response\ApiResponse;

/**
 * Stock service for inventory management, transfers, etc.
 */
class StockService extends BaseService
{
    /**
     * Query stock information
     */
    public function query(array $params = []): ApiResponse
    {
        return $this->call('stock_query.php', $this->filterParams($params));
    }

    /**
     * Push stock transfer
     */
    public function pushTransfer(array $transferData): ApiResponse
    {
        $this->validateRequired($transferData, ['transfer_info']);

        return $this->call('stock_transfer_push.php', [
            'transfer_info' => $this->encodeIfArray($transferData['transfer_info']),
        ]);
    }

    /**
     * Query stock transfer
     */
    public function queryTransfer(array $params = []): ApiResponse
    {
        return $this->call('stock_transfer_query.php', $this->filterParams($params));
    }

    /**
     * Push stockin order
     */
    public function pushStockinOrder(array $orderData): ApiResponse
    {
        $this->validateRequired($orderData, ['stockin_info']);

        return $this->call('stockin_order_push.php', [
            'stockin_info' => $this->encodeIfArray($orderData['stockin_info']),
        ]);
    }

    /**
     * Query stockin order
     */
    public function queryStockinOrder(array $params = []): ApiResponse
    {
        return $this->call('stockin_order_query.php', $this->filterParams($params));
    }

    /**
     * Push stockout order
     */
    public function pushStockoutOrder(array $orderData): ApiResponse
    {
        $this->validateRequired($orderData, ['stockout_info']);

        return $this->call('stockout_order_push.php', [
            'stockout_info' => $this->encodeIfArray($orderData['stockout_info']),
        ]);
    }

    /**
     * Query stockout order
     */
    public function queryStockoutOrder(array $params = []): ApiResponse
    {
        return $this->call('stockout_order_query.php', $this->filterParams($params));
    }

    /**
     * Push stockin transfer
     */
    public function pushStockinTransfer(array $transferData): ApiResponse
    {
        return $this->call('stockin_transfer_push.php', 
            $this->filterParams($transferData)
        );
    }

    /**
     * Push stockout transfer
     */
    public function pushStockoutTransfer(array $transferData): ApiResponse
    {
        return $this->call('stockout_transfer_push.php', 
            $this->filterParams($transferData)
        );
    }

    /**
     * Sync stock by PD (盘点)
     */
    public function syncByPd(array $pdData): ApiResponse
    {
        return $this->call('stock_sync_by_pd.php', 
            $this->filterParams($pdData)
        );
    }

    /**
     * Query stock PD order
     */
    public function queryPdOrder(array $params = []): ApiResponse
    {
        return $this->call('stock_pd_order_query.php', $this->filterParams($params));
    }
}